<template>
  <el-dialog v-model="visible" title="新建货车" :before-close="handleClose">
    <el-form :model="form" label-width="120px">
      <el-form-item label="车牌号">
        <el-input v-model="form.num"/>
      </el-form-item>
      <el-form-item label="车辆类型">
        <el-input v-model="form.type"/>
      </el-form-item>
      <el-form-item label="车辆拥有者">
        <el-input v-model="form.owner"/>
      </el-form-item>
      <el-form-item label="所属仓库">
        <el-input v-model="form.wid"/>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="sureEditAccount">确认</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
import {reactive} from "vue";
import {createTruck} from "@/scripts/data/truck";

export default {
  name: "TruckCreate",
  props: ['callback'],
  data() {
    return {
      visible: false,
      change: false,
      form: reactive({
        num: '',
        type: '',
        owner: '',
        wid: '',
        tid: '',
      })
    }
  },
  methods: {
    sureEditAccount() {
      this.change = true;
      createTruck(this.form, this.callback)
    },
    handleClose() {
      this.visible = false;
      if (!this.change) {
        this.callback(-1);
      }
    },
  },
  mounted() {
    this.visible = true;
  }
}
</script>

<style scoped>

</style>